PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 8th, 2013, 02:03 PM
nbasso713 nbasso713 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 64 nbasso713 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 36 m 11 sec
Reputation Power: 1
Struggling to convert mysql to mysqli

I'm not sure why i'm having such a difficult time, but my mysqli $link keeps returning null even after I have declared it as a variable.

I'm able to connect to my database using everything inline on the same page, but my function files are producing the null errors.

I have also added the following to the top of a function file:

PHP Code:
require (dirname(__FILE__).'/../*/*/*/*/*/*.php')

$host$Host// Host name
$username$Username// mysqli username
$password$Password// mysqli password
$db_name$Database// Database name

// Connect to server and select databse.
global $link;

$link mysqli_connect($host$username$password$db_name)or die("cannot connect"); 


Even with the global $link being set on the same page as the functions being used null is still being returned.

Any help would be greatly appreciated because at this point it seems like such a pain in the *** that I should just to go back to mysql functions.

Reply With Quote
  #2  
Old January 8th, 2013, 02:08 PM
portcitysoftwar portcitysoftwar is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 163 portcitysoftwar User rank is Sergeant (500 - 2000 Reputation Level)portcitysoftwar User rank is Sergeant (500 - 2000 Reputation Level)portcitysoftwar User rank is Sergeant (500 - 2000 Reputation Level)portcitysoftwar User rank is Sergeant (500 - 2000 Reputation Level)portcitysoftwar User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 13 h 18 m 54 sec
Reputation Power: 17
You are using the syntax of old mysql extension. I am still getting the hang of MySqlI however i preffer using object oriented code and i use the following connection method
PHP Code:
 $mysqli = new mysqli("127.0.0.1""user""password""database"3306);
if (
$mysqli->connect_errno) {
    echo 
"Failed to connect to MySQL: (" $mysqli->connect_errno ") " $mysqli->connect_error;



sorry just read the procedural methodand your syntax was correct

Quote:
Originally Posted by nbasso713
I'm not sure why i'm having such a difficult time, but my mysqli $link keeps returning null even after I have declared it as a variable.

I'm able to connect to my database using everything inline on the same page, but my function files are producing the null errors.

I have also added the following to the top of a function file:

PHP Code:
require (dirname(__FILE__).'/../*/*/*/*/*/*.php')

$host$Host// Host name
$username$Username// mysqli username
$password$Password// mysqli password
$db_name$Database// Database name

// Connect to server and select databse.
global $link;

$link mysqli_connect($host$username$password$db_name)or die("cannot connect"); 


Even with the global $link being set on the same page as the functions being used null is still being returned.

Any help would be greatly appreciated because at this point it seems like such a pain in the *** that I should just to go back to mysql functions.

Reply With Quote
  #3  
Old January 8th, 2013, 02:33 PM
ManiacDan's Avatar
ManiacDan ManiacDan is offline
Likely to be eaten by a grue.
Dev Shed God 10th Plane (9500 - 9999 posts)
 
Join Date: Oct 2006
Location: Pennsylvania, USA
Posts: 9,791 ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)  Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 2 Months 3 Weeks 14 h 53 m 20 sec
Reputation Power: 6112
Are you saying that $link is null inside functions? That's what's supposed to happen. If you want to use a variable inside a function, you have to pass it in. It's a function of PHP's variable scope
__________________
HEY! YOU! Read the New User Guide and Forum Rules

"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Struggling to convert mysql to mysqli

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap