PDA

View Full Version : php 5.0.2



ZURKE
12-19-2004, 09:48 PM
Hello, as you will soon realize I am new to this database thing. My situation appears to be in trying to connect to a particular MYSQL database. It seems I can connect to MYSQL but when I try and "select" a database once within I end up with warnings and no connection to that database. I have tried a number of changes(in the dark I might ad) relating to "mysqli" instead of "mysql" in querying.

I am using:
PHP 5.0.2
Apache 1.3.33
MySQL 4.1.7
Zend Optimizer 2.5.5
phpMyAdmin 2.6.0-pl2
Perl 5.8.4

Here is what I have,
$user = "xxxx";
$host = "localhost";
$password = "xxxx";
$database = "signature";
$connection = mysqli_connect($host,$user,$password);
if (!$connection){
echo ("<b>unable to connect to the mysql server at this time</b>");
exit();
}

mysqli_select_db('$connection','$database'); line #19
if(!mysqli_select_db('database')){ line #20
exit("<b>unable to connect to signaturedb</b>");
}

mysqli_query(query);
$result = mysqli_query("SELECT * FROM sig");
if (!$result){
exit("<b>unable to retrieve sig mysql_error()</b>");
}

while ($row = mysqli_fetch_array(result));{
echo ($row[sig]);
}

and this is what I get:

Warning: mysqli_select_db() expects parameter 1 to be mysqli, string given in c:\AppServ\www\onemoretime.php on line 19
Warning: mysqli_select_db() expects exactly 2 parameters, 1 given in c:\AppServ\www\onemoretime.php on line 20
unable to connect to signaturedb

Any assistance would be greatly appreciated as I have few hairs left.

Paul Komski
12-20-2004, 06:39 PM
Not sure and have only used mysql not mysqli but should the variable $connection perhaps be a string:-
$connection = mysqli_connect($host,$user,$password);
eg perhaps be written as:-
$connection = "mysqli_connect($host,$user,$password)";

And
if(!mysqli_select_db('database')){ line #20
should perhaps be
if(!mysqli_select_db('$connection','$database')){ line #20
or similar with two parameters

tip
Leave out the line # refs and post the code, as is, (in the original) inside php tags - eg -



$user = "xxxx";
$host = "localhost";
$password = "xxxx";
$database = "signature";
$connection = "mysqli_connect($host,$user,$password)";
if (!$connection){
echo ("<b>unable to connect to the mysql server at this time</b>");
exit();
}

mysqli_select_db('$connection','$database');
if(!mysqli_select_db('$connection','$database')){
exit("<b>unable to connect to signaturedb</b>");
}

mysqli_query(query);
$result = mysqli_query("SELECT * FROM sig");
if (!$result){
exit("<b>unable to retrieve sig mysql_error()</b>");
}

while ($row = mysqli_fetch_array(result));{
echo ($row[sig]);
}

ZURKE
12-21-2004, 08:58 PM
Thanks Paul,

I found it. It was the quote around $connection and $database on line #19.
Also line #20 I not only removed the quote but the whole parameter.
It now seems to retrieve what I want so I am a bit further.:)

I am not sure if there is a real big difference between MYSQL 5. and 4. but what I am reading is not working in application using MYSQL 5.. I will be alot happier when the come out with a no brain reference for 5. Thanks again.

Paul Komski
12-21-2004, 09:16 PM
v4 does all I need for the moment with php from iis (where phpmyadmin works well) and as the backend for VB apps and MS Access using mysql connector/odbc 3.51. The other useful admin tool is WinMySQLAdmin 1.4
Since everything's working sweet I'm in no hurry to upgrade.