LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-18-2004, 05:29 PM   #1
bm1
Member
 
Registered: Nov 2002
Location: NZ
Distribution: freeBSD, slack
Posts: 156

Rep: Reputation: 30
php4 mysql connectivity


im trying to connect to mysql through a php script, heres the script

<?
trim($firstName);
trim($lastName);
trim($age);

if(!$firstName || !$lastName || !$age) {
echo "you did not enter all the values<br>";
exit;
}

$firstName = addslashes($firstName);
$lastName = addslashes($lastName);
$age = intval($age);

@ $db = msql_pconnect("localhost", "root", "password");
if(!$db) {
echo "Error: could not connect to the msql database<br>";
exit;
}

echo "connection to the database was a success<br>";

?>

i know i shouldnt use the root for access to mysql, this is only to see if i can get a connection. i get no errors just a blank page. is this something in my configuring of LAMP or my programming. thanks
 
Old 02-18-2004, 06:04 PM   #2
bm1
Member
 
Registered: Nov 2002
Location: NZ
Distribution: freeBSD, slack
Posts: 156

Original Poster
Rep: Reputation: 30
i was just wondering, i use slackware 9.0 do i have to open any ports for this. i use mysql and apache that came with the slack install cd. i dont know why i use the @ before i connect the dastabase but i get an error that php does not recognise the function if i dont use it. my ip address of my comp is assisgned through dhcp from my router. if that helps. thanks
 
Old 02-18-2004, 11:41 PM   #3
patpawlowski
Member
 
Registered: Mar 2003
Location: Centreville, Virginia
Distribution: Mandrak, Red Hat
Posts: 163

Rep: Reputation: 30
I don't know if this will help but this is the function that I use to open our mysql database:

<?php
function opendatabase(){
global $connection;
$connection = mysql_connect("localhost", "uniforms", "password" or die(mysql_error());
mysql_select_db("siegels", $connection) or die(mysql_error());
}
?>
 
Old 02-19-2004, 06:01 PM   #4
bm1
Member
 
Registered: Nov 2002
Location: NZ
Distribution: freeBSD, slack
Posts: 156

Original Poster
Rep: Reputation: 30
thanks i got it working and i dont understand why? i used your code

$connection = mysql_connect("localhost", "uniforms", "password") or die(mysql_error());

it worked with the or die(mysql_error()); at the end of the connection function, and i dont know why thanks for helping me patpawlowski. if anyone knows why this is could you share it with me.
 
Old 02-19-2004, 06:23 PM   #5
bm1
Member
 
Registered: Nov 2002
Location: NZ
Distribution: freeBSD, slack
Posts: 156

Original Poster
Rep: Reputation: 30
yeah i found the answer and its simple as. i feel like the newest newbie of newbies from newbieville. it was a simple syntax error. i spent 3 days looking for the answer doing alot of reading (which wasnt a waste of time) looking for some config problem. sorry for wasting space on your server / with such a simple question
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP4-MySQL TehIan Linux - Software 2 06-30-2005 01:51 PM
MySQL commands not recognised by PHP4 Christopher Linux - Software 1 12-09-2004 05:16 PM
php4 mysql, installation, php-pages with mysql info stay empty dnla Linux - Software 2 03-14-2004 02:54 PM
PHP4 MySQL configuration Gilion Linux - Software 7 02-02-2004 10:03 AM
apache2 prefork + php4 + mysql rymonree Linux - Software 1 09-06-2003 02:03 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:39 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration