using mysql database using php
I need little help on configuring apache,mysql and php. First will tell whatever i had did till now. 1)i installed the apache 2, php5, and mysql 5. 2)then i edited the httpd.conf file for php and now i can run php files in apache.
But i m not able to connect to mysql from php. I searched about it but got confused so need some help on whether i need to do some extra setting or anything else.
please help:)
harry_potter28 wrote: i got this error: mysql_connect() is not defined
i used the connection string properly that i m sure but may be there are some setting that i need to change.
Post what code you use to connect to the database:
here is little sample that I use for localhost connection:
<?php
function sql(){
$database = 'nameofdatabase';
$host = '127.0.0.1';
$db_user = 'root';
$db_pass = 'secretpassword';
$con = mysql_connect($host,$db_user,$db_pass) or die(mysql_error());
mysql_select_db($database,$con);
return $con;
}
function endsql(){
mysql_close();
}
?>
which you then include before the sql connection and use it as : $connect = sql(); etc
And no you shouldn't need any extra settings, except knowing your databse password and create database with new name, or use default database "mysql"
Ok, try to do that:
You should have Apache installed in "c:\apache\apachegroup" or something similar; PHP installed in "c:\php" Mysql installed in "c:\mysql"
open the httpd.conf (c:\apache\apachegroup\conf\httpd.conf) and add:
markup ScriptAlias /php/ "c:/php/" AddType application/x-httpd-php .php Action application/x-httpd-php "/php/php-cgi.exe"
Go to php directory c:\php then rename php.ini-dist to php.ini (or make a new php.ini based on old php.ini file), and make sure u set the right extension:
extension_dir = "c:\php\ext"
extension=php_mysql.dll
Cyph3rHell wrote: Ok, try to do that:
You should have Apache installed in "c:\apache\apachegroup" or something similar; PHP installed in "c:\php" Mysql installed in "c:\mysql"
open the httpd.conf (c:\apache\apachegroup\conf\httpd.conf) and add:
markup ScriptAlias /php/ "c:/php/" AddType application/x-httpd-php .php Action application/x-httpd-php "/php/php-cgi.exe"
Go to php directory c:\php then rename php.ini-dist to php.ini (or make a new php.ini based on old php.ini file), and make sure u set the right extension:
extension_dir = "c:\php\ext"
extension=php_mysql.dll
ok thanks done rest of the part except extension will do it and then see whether it works
Hey guys what about using mysqli (MySQL Improved Extension)?
<?php
$dbinfo = parse_ini_file('db.ini');
$conn = new mysqli($dbinfo['SERVER'], $dbinfo['USER'], $dbinfo['PASSWORD'], $dbinfo['DB']);
//Check for errors
if ($mysqli_connect_error)
{
die("Connection failed --> " . mysqli_connect_error());
}
echo "Connected!";
$query = "..";
if ($conn->query($query))
echo "Done :)\n";
else
echo "Failed :(\n";
$conn->close();
?>
it seems to be nicer with OOP
clone4 wrote: wow object for mysql, just like in perl i LOVE it, thx Cyph3rHell(does it come with default php install)?
nope, u should install it… read this: http://it.php.net/mysqli
To enable mySQL for use in PHP5, you have to do the following:
- Make sure you have valid php.ini file in <Apache_dir>.
- Copy libmysql.dll to the system32 directory (in Windows installation directory). (php_mysql.dll won’t load without doing this!)
- Set the extension_dir in php.ini to the ext directory of your PHP installation directory - typically "extension_dir = <PHP_installation_dir>\ ext".
- Enable the mySQL extension in php.ini by un-commenting the line "extension = php_mysql.dll".
- Restart Apache Server.
i m having one more question please help when ever i have to open my files in browser i type http://localhost/folder/files.html
instead of typing localhost can i change to the name like www.mywebsite.com and if yes how?
So that i can type http://www.mywebsite.com/folders/files.html to open my files.
i m having one more question please help when ever i have to open my files in browser i type http://localhost/folder/files.html
instead of typing localhost can i change to the name like www.mywebsite.com and if yes how?
So that i can type http://www.mywebsite.com/folders/files.html to open my files.
http://en.wikipedia.org/wiki/DNS_hosting_service
If you want to go free, register at dyndns.com.
You can get a website.ath.cx domain, that's the shortest free one. You can also contact Aldarhawk for (cheap) payed DNS + hosting.
Is the domainname supposed to be for localhost development. In that case you can spoof a DNS name for local machines.
Are you running Windows or Linux?
There's a file in both of them called hosts, in Windows it's located in C:\Windows\system32\drivers\etc, and in linux it's located in /etc.
Just add the line:
markup127.0.0.1 www.mydomain.com
and of course replace mydomain with whatever domain you want.