Re: catch the error

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 2009-02-26 at 12:28 -0500, PJ wrote:
> What is wrond with this file? same identical insert works from console
> but not from this file :-(
> 
> <html>
> <head>
>     <title>Untitled</title>
> </head>
> 
> <body>
> <?
> //include ("lib/db1.php");    // Connect to database
> mysql_connect('biggie', 'user', 'password', 'test');
> $sql1 = "INSERT INTO example (name, age) VALUES ('Joe Blow', '69')";
> $result1 = mysql_query($sql1,$db);
> if (!$result1) {
>   echo("<P>Error performing 1st query: " .
>        mysql_error() . "</P>");
>   exit();
> }
> ?>
> 
> </body>
> </html>
> 
> Seems to be good to print out the error message, but that's all. db not
> written.
> 
> -- 
> 
> Phil Jourdan --- pj@xxxxxxxxxxxxx
>    http://www.ptahhotep.com
>    http://www.chiccantine.com
> 
> 
I'd say it was the way you are trying to connect to your database. This
is how it's done:

$db_host = 'localhost';
$db_user = 'root';
$db_password = '';
$db_name = 'database_name';

$db_connect = mysql_connect($db_host, $db_user, $db_pass);
$db_select = mysql_select_db($db_name, $db_connect);

You see, first you have to cerate a connection to the database server,
then you have to select your database on that connection. In your
example, 'biggie' is the name of a server where your database resides,
and 'test', well, what can I say? This 4th parameter should be a boolean
indicating whether or not a new connection should be made upon
successive calls to mysql_connect.


Ash
www.ashleysheridan.co.uk


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux