problem when runing a funciton


Posted on 16th Feb 2014 07:03 pm by admin

I am trying to connect to database using a funciton in a functions.php

<?php
function connect_db_Blog (){
$con=mysql_connect("localhost","root","");
$db=mysql_select_db("blog",$con);
}
?>
which I then include with
include ("scripts/php_functions.php");

but when I run a code with

connect_db_Blog();

var_dump($db);
if (!$db) {

echo "sorry, cannot connect to database";

} else {
here comes some code..

I get: sorry , cennot connect to database message.

when I listen for $db with
var_dump($db);
I get int(0);
instead of int(1) which is needed to proceed with the code.

If I just try to connect to database without the include I dont get the error message i.e. .

No comments posted yet

Your Answer:

Login to answer
311 Like 17 Dislike
Previous forums Next forums
Other forums

Simple code help with redirects
I am trying to figure out a redirect script that detects if the browser is IE 7 and if it does, redi

mysql_affected_rows() usage
Possibly a MySQL issue, but the function that is not behaving in the anticipated way is a PHP functi

Quick fix: Conditional statement with an array
Hi, I'm getting the temperature value off of the Environment Canada website along with the icon file

strptime() equivalent for php4 ?!
Greetings!

this is my first post, thank you in advance for your replies.

Well, the ti

PHP Programming error. Please help!
Hi there,

Am making a website for a friend and have encountered a problem that i need fixing

Preg_match question
I want to use preg_match to make sure a string is always 6 characters long and only contains 0-9 and

Printing issues with xMII 11.5
For some reason, we have one report (and only one) that is giving us fits when trying to print. The

Comparing MySql data and arrays.
I have a mysql table set up like this:
idsubjectbodyuseriddatetimetags1blog subjectblog body111|2

extending tidy
I have problem with type-hinting and extending tidy. This code creates error:
Code: class cMyTidy

Insert numbers from Barcode scanner into online php page
I have a real big problem, Here is what I'm trying to do. I have a Intermec CN3 handheld computer th

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash