somiadiscon 01-25-2007, 04:05 AM hi all,
i was done one php connection with apach, mysql i this somthings wrong with it could you pls anyone can help me to figure out what happend to this code :)
file name is this db_config.php
<?php
$db_host = "localhost";
$db_user = "php";
$db_password = "fo";
$db_name = "babyDB";
?>
////////////
file name of this temp_con.php
<?php
require ($_SERVER["DOCUMENT_ROOT"]."/config/db_config.php");
$connection = @mysql_connect($db_host, $db_php, $db_password);
echo "connection made";
?>
thanx
ConnorB 01-25-2007, 04:12 AM Instead of using "require ($_SERVER["DOCUMENT_ROOT"]."/config/db_config.php");" just use:
<?
include('config/db_config.php');
?>
(Without the <? and the ?> because you already have it.) Or, you could do this:
<?
$root = $_SERVER['DOCUMENT_ROOT']."config/db_config.php";
include($root);
?>
aedrin 01-25-2007, 04:19 PM It would help if you told us which part is not working.
There should be no reason to include the Document Root in the include. Unless your hosting does not have a proper include path set up.
Also, it is generally advised to use <?php instead of <?
ConnorB 01-26-2007, 02:10 AM I used "<?" because it was shorter and easier for me to tell what to do with. I only use "<?php" when the file I am writing has some sort of HTML in the content of the file. It's just how I roll.
somiadiscon 01-26-2007, 05:36 AM hi ConnorB,
what you are gave to me was not working same things still i cant see what the echo hold or no error display just a blank page why is that help me if i change password php file error has to show isn't it but this time it will not i create a database call babyDB; using mysql (using dos commands) so there i create a user call php, put password and host every things working when i am try to login to database using mysql command but when im using Browser it will not display anythings
cookieboi 01-26-2007, 07:11 PM hi ConnorB,
what you are gave to me was not working same things still i cant see what the echo hold or no error display just a blank page why is that help me if i change password php file error has to show isn't it but this time it will not i create a database call babyDB; using mysql (using dos commands) so there i create a user call php, put password and host every things working when i am try to login to database using mysql command but when im using Browser it will not display anythings
try speaking english??:confused:
i would use this to connect..
<?php
// This is an example of config.php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'password';
$dbname = 'phpcake';
?>
<?php
// This is an example opendb.php
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);
?>
so when you want to connect, you need this code;
<?php
include 'config.php';
include 'opendb.php';
// ... do something like insert or select, etc
?>
But remember to close the connection after you have done something to the database so make another file..
<?php
// an example of closedb.php
// it does nothing but closing
// a mysql database connection
mysql_close($conn);
?>
and then include it where you need it..
<?php
include 'config.php';
include 'opendb.php';
// ... do something like insert or select, etc
include 'closedb.php';
?>
happy coding
Jamez.
somiadiscon 01-29-2007, 04:52 AM hi cookieboi,
i know my english is not good, but you can read right. however now this time i got error msg
"Fatal error: Call to undefined function mysql_connect() in C:\PHP\uploadtemp\sql.php on line 3"
could you pls figure out this matter thanx
somiadiscon
cookieboi 01-29-2007, 03:55 PM Hi mate, i cant see any error in it, the only thing that i can see that might be wrong is that on the opendb page, remove the $conn from the beggining so it looks like this,
<?php
// This is an example opendb.php
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);
?>
<?php
// This is an example opendb.php
mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);
?>
and then don't include the closedb.php file.
Apart from that suggestion i cant see much else wrong with it. you may need to configure your server perhaps?
schotte 01-29-2007, 06:27 PM Hey,
removin $conn won't help the fact that the MySQL functions are not defined. PHP has to be installed with MySQL. Here are some more tips on how to do it: PHP.net (http://uk.php.net/manual/en/ref.mysql.php). It is also a good source for small code snippets that should always work.
somiadiscon 01-30-2007, 08:54 AM hi schotte,
thank you for your help i am serching now, why the function is not working i know you are right. becoz Mysql and php there should be bridge right may be it don't work porperly isn't it thank you again all of you helping me still i am try to figure out problem
somiadiscon 02-05-2007, 03:58 AM hi schotte,
here mr. i couldn't i don't know why is that but i am not sure whether it is the version i am using. Now i am using apache 2.0.5 and php 5 MySQL 4.x.x so i don't know it was install without any issue MySQL is working when i am try to create a database or delete database using command prompt dos command is working perfect. Thing is now i am install AMP software with all the packeges it has that is working without any problem. why is that
schotte 02-05-2007, 09:12 AM So if I understand you correctly, you didn't have MySQL installed?
Now you got AMP installed and it still does not work?
If so, have you installed PHP with MySQL support? You can check either the php.ini file or create a file with the following code to check:
<?php
phpinfo();
?>
somiadiscon 02-06-2007, 03:55 AM hi Schotte,
i check with this code earlier there i found MySQL is not working if it is working properly, it has to show php info page i know that that is why i want to know kind of what issue i have at the moment, other things is i am using 64bit processor is there is any issue with that process performance
<?php
phpinfo();
?>
|
|