Page 1 of 1
access s9y database
Posted: Mon Jan 16, 2012 9:43 pm
by Don Chambers
I had the need to add a batch of rows to one of the s9y tables. php and mysql are not really my thing, but I did accomplish my objective with this:
Code: Select all
<?php
$con = mysql_connect("localhost","my_db_username","my_db_password");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db_name", $con);
for ($i = 1; $i < 2672; $i++) {
$sql="INSERT INTO s9y_entryproperties (entryid, property, value) VALUES($i, 'ext_body_access', '5^3^2^1')";
if (!mysql_query($sql,$con)) {
die('Error: ' . mysql_error());
}
}
echo "Record(s) added";
mysql_close($con)
?>
Was there a better/easier way to do it? Plug into s9y which already knows things like the server, database user, password, etc?
Re: access s9y database
Posted: Mon Jan 16, 2012 11:10 pm
by Don Chambers
I figured it out:
Code: Select all
<?php
include 'serendipity_config.inc.php';
for ($i = 1; $i < 2672; $i++) {
echo serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}entryproperties (entryid, property, value) VALUES($i, 'ext_body_access', '5^3^2^1')");
}
echo '<br /> ' , ($i-1), " record(s) added";
?>
Each cycle through the loop echos a "1" to the screen. Is there a way to suppress that?
Re: access s9y database
Posted: Tue Jan 17, 2012 12:44 pm
by onli
Yes, omit the echo before serendipity_db_query.
Re: access s9y database
Posted: Tue Jan 17, 2012 4:14 pm
by Don Chambers
onli wrote:Yes, omit the echo before serendipity_db_query.
Any negative associated with that?
Re: access s9y database
Posted: Tue Jan 17, 2012 7:10 pm
by Don Chambers
Don Chambers wrote:onli wrote:Yes, omit the echo before serendipity_db_query.
Any negative associated with that?
Works beautifully... I thought removing the "echo" would suppress error messages, but it does not. If I actually wanted to hide error messages, that would have been INSERT IGNORE INTO....
Re: access s9y database
Posted: Tue Jan 17, 2012 8:07 pm
by Timbalu
But...,
.... Don ....,
you still know you are trying to loop this INSERT INTO statement 2672 times!
Is that really what you wanted to do? Or is it just a test to kill your system?

Re: access s9y database
Posted: Tue Jan 17, 2012 10:24 pm
by Don Chambers
I have a template that fakes plugin functionality (see
http://board.s9y.org/viewtopic.php?f=5&t=14984).
It works by storing values for custom properties in the entryproperties table. I added it to an existing site which has 2600+ existing entries. For those entries to have these properties, I either have to edit each entry one at a time, or simply populate the entryproperties table with these values.
Re: access s9y database
Posted: Wed Jan 18, 2012 9:12 am
by Timbalu
Yes, I already thought you were trying something like this.
And I remember this mentioned thread as keeping some very interesting possibilities.
Again, I am still waiting for more cool ideas how to use it for common or special problems.
...for your code it might be better to gather the INSERT INTO statement into an array, like
$hold[] = "INSERT INTO...";
and execute the array afterwards once with
serendipity_db_query($hold);