PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
function Connect_to_db($filename)
{
include($filename);
$cxn = mysqli_connect($host,$user,$password)
or die ("Couldn't connect to server.");
$db = mysqli_select_db($cxn,$database)
or die ("Coulden't select database.");
}
?>
and here is the kicker.....when i change the password in the and user name to access the database in the main file(the main file being simply)
<?php
function Connect_to_db($filename)
{
require $filename;
if ( !isset($host,$user,$password,$database) ) {
die('one or more required connection parameters not set');
}
echo "Debug: mysqli_connect($host,$user,$password)";
$cxn = mysqli_connect($host,$user,$password)
or die ("Couldn't connect to server.");
$db = mysqli_select_db($cxn,$database)
or die ("Coulden't select database.");
}
?>
but im using xampp....that link tells me to connect to my database using CMD but when i try that i get a error that says bad syntax...so next i tried just going to the folder in xampp that mySQL is installed in and it had a .exe when i clicked it it didnt promt me for anything it was just a blank cmd screen without a path and just a prompt....what do i do
one or more required connection parameters not set. can u explain to me the difference in your snippet....why it gave a different error and why mine gave a connection error? how can i avoid the connection issue in the future?
so what do i do? i dont mean to be a neusence but im new to the whole php deal and you said that its testing to see whether or not the password is correct...if i changed the password the error is the same...thats what i dont understand...if im thinking correctly its wanting to connect to mySQLadmin right...so if i put in the correct username and password it should work right? but its not....why?
and what did you mean by
volka wrote:My version tests, wether there are those variables you want to use with mysqli_connect or not. At least one is not.
<?php
function Connect_to_db($filename)
{
include($filename);
$cxn = mysqli_connect($host,$user,[[[[[[[[[[[[$password]]]]]]]]]]]]]])
or die ("Couldn't connect to server.");
$db = mysqli_select_db($cxn,$database)
or die ("Coulden't select database.");
}
?>
@ole= i understand what u are trying to say but if you would have read the message i wrote earlier to its completion you would have read that i tried to change the password to see if that would fix the problem and it didnt, and then i asked volka to explain the difference in the code that he wrote and the tutorial that i was following so that i could explain how it worked(thanx volka btw). Ive never worked with either of these languages (php and mySQL) before now so there is alot i dont understand and im following a tutorial that dosent cover debugging or error handling (and not to mention has alot of typos) to get a larger product for my company complete so the comment with the brackets around the password was hardly necessary.
ok....i think i get it....but what password is it looking for is it looking for the mySQLadmin, the phpMYAdmin() bc thats where i created the database in....or am i still miles away from the answer...anyone? also if im thinking correctly the line
is testing to see whether or not those variables are set. and in the file it points to somefile.php they are so thats why im not understanding. can someone explain to me what im doing wrong?
I'm not sure you did.
You noticed the difference
$passwd <- $passwd = "****";
$password <- mysqli_connect($host,$user,$password)
and have corrected that error?