Follow us on Twitter!
Capitalism is an Island of wealth in a sea of poverty
Wednesday, April 23, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 27
Guests Online: 18
Members Online: 9

Registered Members: 82882
Newest Member: imtheboss
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Page 1 of 2 1 2 >
Author

using mysql database using php


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 08-02-09 17:21
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 helpSmile
Author

RE: using mysql database using php


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 08-02-09 17:26
maybe u can start posting what error u got when u try to connect to db...


Author

RE: using mysql database using php


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 08-02-09 17:35
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.
Author

RE: using mysql database using php


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 08-02-09 17:38
Are u using win?


Author

RE: using mysql database using php


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 08-02-09 17:39
yes windows xp
Author

RE: using mysql database using php

clone4
Member



Posts: 586
Location: He is back and he's bad!
Joined: 25.11.07
Rank:
Mad User
Posted on 08-02-09 17:42
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:
Code

<?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"


[img][/img]img164.imageshack.us/img164/5713/perlvl0.jpg

clone4.freehostia.com/ubuntu_3.png
spyware - "They see me trollin'..."
<yaragn> ever seen that movie? The Matrix?
<yaragn> with those green lines of flying text?
<yaragn> *THAT'S* Perl



Edited by clone4 on 08-02-09 17:45
clone_4@hotmail.com
Author

RE: using mysql database using php


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 08-02-09 17:43
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:
Code

      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




Edited by on 08-02-09 17:43
Author

RE: using mysql database using php


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 08-02-09 17:47
This is the code that i m using


<?php
$con = mysql_connect("localhost","root","password"Wink;
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("dbname", $con);
mysql_query("insert into username ($name,$address,$age,$cno,$username,$password)"Wink;
mysql_close($con);
?>

Author

RE: using mysql database using php


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 08-02-09 17:50
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:
Code

      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
Author

RE: using mysql database using php


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 08-02-09 17:52
Hey guys what about using mysqli (MySQL Improved Extension)?

Code

<?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




Edited by on 08-02-09 17:54
Author

RE: using mysql database using php

clone4
Member



Posts: 586
Location: He is back and he's bad!
Joined: 25.11.07
Rank:
Mad User
Posted on 08-02-09 17:55
wow object for mysql, just like in perl i LOVE it, thx Cyph3rHell(does it come with default php install)?
and sorry h_p the script seems alright, dunno what else could it beSmile


[img][/img]img164.imageshack.us/img164/5713/perlvl0.jpg

clone4.freehostia.com/ubuntu_3.png
spyware - "They see me trollin'..."
<yaragn> ever seen that movie? The Matrix?
<yaragn> with those green lines of flying text?
<yaragn> *THAT'S* Perl

clone_4@hotmail.com
Author

RE: using mysql database using php


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 08-02-09 17:57
checked the extension part and its already there so problem not solved yet.
Author

RE: using mysql database using php


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 08-02-09 17:58
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. . .


Author

RE: using mysql database using php


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 08-02-09 18:00
harry_potter28 wrote:
checked the extension part and its already there so problem not solved yet.


are you sure your daemon is started?


Author

RE: using mysql database using php


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 08-02-09 18:02
yes
i had checked these things 3 to 4 times. stopped all the servers then started again but nothing working.
Author

RE: using mysql database using php


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 08-02-09 18:06
Since PHP5 you have to enable the mysql extention, are u sure u have it enabled in php.ini file?


Author

RE: using mysql database using php


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 08-02-09 18:10


[PHP_MYSQL]
extension=php_mysql.dll


this is the part of the php.ini file if that what u r asking.
Author

RE: using mysql database using php


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 08-02-09 18:13
To enable mySQL for use in PHP5, you have to do the following:

1. Make sure you have valid php.ini file in <Apache_dir>.
2. Copy libmysql.dll to the system32 directory (in Windows installation directory). (php_mysql.dll won’t load without doing this!)
3. Set the extension_dir in php.ini to the ext directory of your PHP installation directory - typically "extension_dir = <PHP_installation_dir>\ ext".
4. Enable the mySQL extension in php.ini by un-commenting the line "extension = php_mysql.dll".
5. Restart Apache Server.



Author

RE: using mysql database using php


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 08-02-09 18:17
u said about having php.ini in apache group folder?

because its not there so if u say i will copy that file there.
reply.
Author

RE: using mysql database using php


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 09-02-09 17:30
guys finally done the connection thanks for all ur help.Smile
Page 1 of 2 1 2 >