[PHP] Re: mysql_query - CREATE DATABASE
R B wrote: Hello, When i create a mysql database with the next command: mysql_query(CREATE DATABASE my_db,$con) In the server is created the database, but usually the name is created with a prefix. In this case: someuser_my_db How can i detect with PHP the complete name of the new database created? Thanks There may be a better way, but off the top of my head, translate this to PHP: use information_schema; select SCHEMA_NAME from SCHEMATA where SCHEMA_NAME like '%_my_db'; Now of course you could have multiples there, like user_my_db and user2_my_db. Not sure about that, maybe it would be the last one in the returned records? -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: mysql_query - CREATE DATABASE
I´m creating a software that use a database, and i want to include a install.php file to install the database of the software. I can create the database in the install.php file with mysql_query(CREATE DATABASE my_db,$con) But when is created, i don´t know the complete name of the database, because a prefix is added. On Mon, Feb 9, 2009 at 12:17 PM, Shawn McKenzie nos...@mckenzies.netwrote: R B wrote: Hello, When i create a mysql database with the next command: mysql_query(CREATE DATABASE my_db,$con) In the server is created the database, but usually the name is created with a prefix. In this case: someuser_my_db How can i detect with PHP the complete name of the new database created? Thanks There may be a better way, but off the top of my head, translate this to PHP: use information_schema; select SCHEMA_NAME from SCHEMATA where SCHEMA_NAME like '%_my_db'; Now of course you could have multiples there, like user_my_db and user2_my_db. Not sure about that, maybe it would be the last one in the returned records? -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: mysql_query - CREATE DATABASE
Shawn McKenzie wrote: R B wrote: Hello, When i create a mysql database with the next command: mysql_query(CREATE DATABASE my_db,$con) In the server is created the database, but usually the name is created with a prefix. In this case: someuser_my_db How can i detect with PHP the complete name of the new database created? Thanks There may be a better way, but off the top of my head, translate this to PHP: use information_schema; select SCHEMA_NAME from SCHEMATA where SCHEMA_NAME like '%_my_db'; Now of course you could have multiples there, like user_my_db and user2_my_db. Not sure about that, maybe it would be the last one in the returned records? Using mysql_list_dbs() and mysql_db_name() would acheive the same, however from the man page of mysql_db_name() there is a neat contib: $result = mysql_query(SELECT DATABASE()); $dbname = mysql_result($result, 0); -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: mysql_query - CREATE DATABASE
I´m looking that i have another problem: I´m making a software to install in any server. The software needs a database, so i want to create a script install.php to create the database when this script is executed. At this point of the instalation, i don´t know none of the users that are defined in mysql. If i use this command: mysql_query(CREATE DATABASE my_db,$con) first i need to connect to mysql with the command mysql_connect But at this point, i don´t know none of the users that are defined in mysql. So, what i do in this case? Thanks On Mon, Feb 9, 2009 at 12:31 PM, Shawn McKenzie nos...@mckenzies.netwrote: Shawn McKenzie wrote: R B wrote: Hello, When i create a mysql database with the next command: mysql_query(CREATE DATABASE my_db,$con) In the server is created the database, but usually the name is created with a prefix. In this case: someuser_my_db How can i detect with PHP the complete name of the new database created? Thanks There may be a better way, but off the top of my head, translate this to PHP: use information_schema; select SCHEMA_NAME from SCHEMATA where SCHEMA_NAME like '%_my_db'; Now of course you could have multiples there, like user_my_db and user2_my_db. Not sure about that, maybe it would be the last one in the returned records? Using mysql_list_dbs() and mysql_db_name() would acheive the same, however from the man page of mysql_db_name() there is a neat contib: $result = mysql_query(SELECT DATABASE()); $dbname = mysql_result($result, 0); -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: mysql_query - CREATE DATABASE
Shawn McKenzie wrote: Shawn McKenzie wrote: R B wrote: Hello, When i create a mysql database with the next command: mysql_query(CREATE DATABASE my_db,$con) In the server is created the database, but usually the name is created with a prefix. In this case: someuser_my_db How can i detect with PHP the complete name of the new database created? Thanks There may be a better way, but off the top of my head, translate this to PHP: use information_schema; select SCHEMA_NAME from SCHEMATA where SCHEMA_NAME like '%_my_db'; Now of course you could have multiples there, like user_my_db and user2_my_db. Not sure about that, maybe it would be the last one in the returned records? Using mysql_list_dbs() and mysql_db_name() would acheive the same, however from the man page of mysql_db_name() there is a neat contib: $result = mysql_query(SELECT DATABASE()); $dbname = mysql_result($result, 0); Scratch the above. This is the db of the current connection. This should work, but again doesn't account for multiple dbs with my_db in the name: $dblist = mysql_list_dbs(); while (list($dbname) = mysql_fetch_row($dblist)) { if (strpos($dbname, 'my_db') !== false) { break; } } However it might be easier to do this: mysql_select_db(information_schema); $result = mysql_query(select SCHEMA_NAME from SCHEMATA where SCHEMA_NAME like '%my_db'); $dbname = mysql_result($result, 0); -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: mysql_query - CREATE DATABASE
R B wrote: I´m looking that i have another problem: I´m making a software to install in any server. The software needs a database, so i want to create a script install.php to create the database when this script is executed. At this point of the instalation, i don´t know none of the users that are defined in mysql. If i use this command: mysql_query(CREATE DATABASE my_db,$con) first i need to connect to mysql with the command mysql_connect But at this point, i don´t know none of the users that are defined in mysql. So, what i do in this case? Thanks Well, obviously the user will have to supply the username and password. There's no way around that. So after you know the username you can create the db and then check if the db exists as you have named it (my_db), and if not check for ($username_my_db), if not that then one of the examples I gave you, or just skip right to listing the databases. -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: mysql_query - CREATE DATABASE
thank you. On Mon, Feb 9, 2009 at 1:14 PM, Shawn McKenzie nos...@mckenzies.net wrote: R B wrote: I´m looking that i have another problem: I´m making a software to install in any server. The software needs a database, so i want to create a script install.php to create the database when this script is executed. At this point of the instalation, i don´t know none of the users that are defined in mysql. If i use this command: mysql_query(CREATE DATABASE my_db,$con) first i need to connect to mysql with the command mysql_connect But at this point, i don´t know none of the users that are defined in mysql. So, what i do in this case? Thanks Well, obviously the user will have to supply the username and password. There's no way around that. So after you know the username you can create the db and then check if the db exists as you have named it (my_db), and if not check for ($username_my_db), if not that then one of the examples I gave you, or just skip right to listing the databases. -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: mysql_query() ERROR
It's not the ) characters, it's the quotes - make sure you addslashes() to all the variables. Also make sure you don't double-slash - depending on your php.ini settings, PHP may automatically slash incoming variables. Bogdan Mike Fifield wrote: This is a query that I am sending to mysql. The problem is that sometimes in the variable $message characters like ) will get posted and when they do it makes mysql die. I can only assume that mysql thinks that the ) in the $message variable is meant to close the sql query, but I am having trouble figuring out how to avoid this. I suppose I could use a regex to replace all special characters with something more sql friendly but I am hoping there is a better way to do this. Thanks for any help. mysql_query(insert into guestbook (gb_entry_id,date,name,email,website_name,website_url,message) values ('',CURDATE(),'$name','$email','$website_name','$website_url','$message')) or die (mysql_error()); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: mysql_query() problem
Brian Rue wrote: Hi, I'm getting the error Warning: Supplied argument is not a valid MySQL result resource from this code: function validateUser($username,$password) { $conn = connectToMySQL(); mysql_select_db($db_name,$conn); $query=select * from members where username='.$username.' AND password='.$password.'; $result = mysql_query($query,$conn); if (mysql_num_rows($result) != 0) { //*this is the line that returns the error* return true; } else { return false; } } I've checked that the connection works, and that the query is what it should be, and the query works when I type it into the terminal. Any ideas? Thanks, Brian Rue I suppose it is fixed in 4.1.1-dev. -- Yasuo Ohgaki -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Re: mysql_query()
I have made this a small script called SQL2PHP, --- html headtitleSQL2PHP/title/head body pre ? /* SQL2PHP v0.1 by [EMAIL PROTECTED] You may use this script as long as you credit the original author */ function parse_sql_stream($all) { $len = strlen($all); $lines = array(); $inquotes = false; $lastquote = ''; $lastch = \xa; $start = 0; $incomment1 = false; $incomment2 = false; $brokestr = ; for ($i=0;$i$len;$i++) { $ch = $all[$i]; // single line comment - ON if ( $ch == '#' !$inquotes) { $incomment1 = true; continue; } // single line comment - OFF if ($incomment1 ($ch == \r || $ch == \n)) { $incomment1 = false; $start = $i; continue; } // multiline comment - ON if (!$inquotes $lastch == '/' $ch == '*') { $incomment2 = true; $brokestr = substr($all, $start, $i - $start - 1); continue; } // multiline comment - OFF if ($incomment2 $ch == '/' $lastch=='*') { $incomment2 = false; $start = $i+1; continue; } // inquote desicions if (($ch == '\'' || $ch=='')) { if (!$inquotes) { $lastquote = $ch; $inquotes = true; } else $inquotes = ( ($lastch == \\ $ch == $lastquote) || ($ch != $lastquote) ); } // new statment decision if ($ch == ';' !$inquotes !$incomment1 !$incomment2) { $lines[] = trim($brokestr . trim(substr($all, $start, $i - $start))); $brokestr = ; $i++; // skip the ';' $start = $i; } // update last read character $lastch = $ch; } // for i return $lines; } function parse_sql_file($filename) { $fp = fopen($filename, 'rb'); $all = fread($fp, filesize($filename)); fclose($fp); return parse_sql_stream($all); } set_time_limit(0); mysql_connect('localhost', 'test', 'test'); $test = parse_sql_file('file3.sql'); for ($i=0; $icount($test);$i++) { $result = mysql_query($test[$i]); if (!$result) { echo Failed at line $i with query:\n{$test[$i]}\nMySql error: . mysql_error() . \n; break; } } echo done!\n; ? /pre /body /html --- file3.sql can contain: --- DROP DATABASE t; CREATE DATABASE t; USE t; # # Table structure for table 'brands' # DROP TABLE /*!32200 IF EXISTS*/ brands; CREATE TABLE /*!32300 IF NOT EXISTS*/ brands ( id int(10) unsigned NOT NULL auto_increment, language tinyint(2) DEFAULT '1' , company varchar(50) , countryid int(10) unsigned , name varchar(50) NOT NULL DEFAULT '' , logo varchar(200) NOT NULL DEFAULT '' , description mediumtext NOT NULL DEFAULT '' , PRIMARY KEY (id) ); # # Dumping data for table 'brands' # INSERT INTO brands VALUES(122,1,NULL,12,Hummer,,); INSERT INTO brands VALUES(2,1,NULL,12,Buick,,); INSERT INTO brands VALUES(3,1,NULL,12,GMC,,); INSERT INTO brands VALUES(4,1,NULL,12,Jeep,,); INSERT INTO brands VALUES(5,1,NULL,12,Ford Motor Company,,); INSERT INTO brands VALUES(6,1,NULL,12,Opel,,); INSERT INTO brands VALUES(7,1,NULL,12,Audi,,); INSERT INTO brands VALUES(8,1,NULL,12,BMW,,); INSERT INTO brands VALUES(9,1,NULL,12,Porche,,); INSERT INTO brands VALUES(10,1,NULL,12,Mercedes,,); INSERT INTO brands VALUES(11,1,NULL,12, Infinity*,,); INSERT INTO brands VALUES(12,1,NULL,12,Isuzu,,); INSERT INTO brands VALUES(13,1,NULL,12,Subaru,,); INSERT INTO brands VALUES(14,1,NULL,12,Suzuki,,); INSERT INTO brands VALUES(15,1,NULL,12,Mazda,,); INSERT INTO brands VALUES(16,1,NULL,12,Mitsubishi Motors,,); INSERT INTO brands VALUES(17,1,NULL,12,Honda,,); INSERT INTO brands VALUES(18,1,NULL,12,Alfa Romeo,,); # as much as you want!!! # --- Hope someone make use of it! I tried it with a SQL file with 32554 lines long! //elias Lallous [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Actually the mysql_query() seems to accept only one statement at a time. Any work around so i can do query suchs: mysql_query( SELECT 1+1; SHOW DATABASES; USE database1; SELECT * FROM table1; ); Just multiple commands seperated with ';' ? (as if using the Mysql command prompt) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]