Re: Don't know why query works this way

From: Date: Wed, 06 Aug 2003 21:15:42 +0000
Subject: Re: Don't know why query works this way
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-29729@lists.php.net to get a copy of this message
Michael, You can select the Database to run the queries on by using mysql_select_db($dbname) after you have connected. for example: $link = mysql_connect($host, $username, $password); mysql_select_db($dbname, $link); $query = "INSERT INTO $table ('joe', 15)"; if(mysql_query($query, $link)) { //blah } else { //error } Hope this helps Craig Roberts "Michael Cortes" <cortesm@fortleboeuf.net> wrote in message news:200308052335.52388.cortesm@fortleboeuf.net... I have been writing my queries like this....... $link = mysql_connect ($host, $username, $password); $query = "insert into $table ('joe', 15)"; if ( mysql_db_query($dbname, $query, $link)) { } But then I was reading that I should use mysl_query instead of mysql_db_query. But I was having a problem with where do i put the $dbname. When I used: mysql_query ($dbname, $query, $link) I got an error message saying i had too many arguments. So I changed it to: mysql_query ($query, $link) I then got an error message saying it didn't know what database I was connected to. I finally got around the problem by including the database name in the query, like so: $query = "insert into $dbname.$table ('joe', 15)"; I shouldn't have to say, but this is a simplified example. I didn't want to include all the fields, tables, values that the true example has. The question is, am I doing this right? Do I have no choice but to retype the $dbname all over the place if I want to use "mysql_query"? Thank in advance for any help. -- Michael Cortes Fort LeBoeuf School District 34 East Ninth Street PO Box 810 Waterford PA 16441-0810 814.796.4795

« previous php.db (#29729) next »