Koozali.org: home of the SME Server

connecting to mysql with php

Axel Magnusson

connecting to mysql with php
« on: January 05, 2003, 01:08:25 AM »
I am runnig E Smith server version 5.1.2 Iam having problems to connect to msql server through a PHP made page this is not working I do it this wat

MYSQL_CONNECT('localhost','user','password');
@mysql_select_db("dbname");
?>
I can connect to it if I make a tunnel with SSH through prot 3306 else I can not connect at all

What is wrong

Axel

Dan Brown

Re: connecting to mysql with php
« Reply #1 on: January 05, 2003, 01:11:12 AM »
Well, I'm not at all sure about the php syntax, but what happens when you try this?

John

Re: connecting to mysql with php
« Reply #2 on: January 05, 2003, 04:33:13 AM »
$login="axel";
$pass ="popcorn";
$db=mysql_connect("localhost",$login,$pass);
mysql_select_db("sales",$db);
$sql="select * from clients";
$result=MySQL_query($sql,$db);
$myrow=MySQL_fetch_array($result);
echo "
" . $myrow["Address"] . "
";
?>

that is if you database is "sales" - your table is "clients" - and your column is "Address".

first you will want to go into sme through ssh and log into mysql as root, then create a database.  "  create database sales;   "
then you would want to ceate a user:
GRANT ALL PRIVILEGES ON sales.* TO axel@localhost  IDENTIFIED BY popcorn WITH GRANT OPTION;

that sets up the database and php can access it, but you still need tables and data in the tables-  hope that helps ;-)

Axel Magnusson

Re: connecting to mysql with php
« Reply #3 on: January 06, 2003, 03:10:39 PM »
This is not helping I can still not contact to mysql. I created this table with the SSH and loged into the mysql. but when loading the page it is blank.