Page 1 of 1

problem connecting to mysql from php

Posted: Thu Feb 19, 2004 1:31 am
by bm1
hi im trying to connect to mysql with a php script and the result is i get nothing on the result page but the <h1>headings<h1>. i know ive used root but this is only for testing purposes.

Code: Select all

<?php

trim($firstName); 
trim($lastName); 
trim($age); 

if(!$firstName || !$lastName || !$age) { 
echo "you did not enter all the values<br>"; 
exit; 
} 

$firstName = addslashes($firstName); 
$lastName = addslashes($lastName); 
$age = intval($age); 

@ $db = msql_pconnect("localhost", "root", "password"); 
if(!$db) { 
echo "Error: could not connect to the msql database<br>"; 
exit; 
} 

echo "connection to the database was a success<br>"; 



?>
could this be a problem with how i have configured apache, php or mysql. any help would be much appreciated.

Posted: Thu Feb 19, 2004 1:58 am
by markl999
Topic says mysql but you've used msql_pconnect ... typo?

Posted: Thu Feb 19, 2004 3:11 pm
by bm1
i get the same result if i use mysql_connect, im told that mysql_pconnect is the same thing except that when you open a connection to a mysql server the connection doesnt shut when your script finishes. so then if you have to make a connection again you already have one. i think the p stands for persistant. or something like that. im new to php.

Posted: Thu Feb 19, 2004 5:35 pm
by Dr Evil
markl999 means :
mysql_pconnect instead of msql_pconnect


But then
Should the connection not be ?:

Code: Select all

<?php
$db = @mysql_pconnect("localhost", "root", "password");
?>

Posted: Thu Feb 19, 2004 6:09 pm
by bm1
yeah sorry about the typo, i have got this working with the help of a friend using

Code: Select all

<?php

 $connection = mysql_connect("localhost", "uniforms", "password") or die(mysql_error());

?>
now this code worked with the

Code: Select all

<?php

or die(mysql_error());

?>
and i dont know why? iam reading thru a book and it doesnt use the or die. help me understand why please

Posted: Thu Feb 19, 2004 6:15 pm
by tim
the or die is just for tesitng purposes, it will display the error (if any at all) so you know how to correct the code.


connect to db OR display error in generic terms

Posted: Thu Feb 19, 2004 6:19 pm
by bm1
thanks for the help. i got it working now which is very cool