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

How do I send data using an html link
Hi

If I have
<a href="main_file.php">

How do I send data t

remove trailing slash from array
I have the following array which contains trailing slashes I need to remove. What is the best way to

MySQL-PHP Query Results Help
Hello all. I'm hoping to be able to get some help in solving a problem with query/rowcount output. I

Upload, SSL and more php help
I recently just installed a ssl cert and do i use https for the whole site or just for the checkout.

mail() says sent but no email received
My code is quite simple:

Code: <?php
$to = "Ty44ler@yahoo.com";
$subje

Problem with PHP code- simple contact form
I'm relativily new to PHP; I know HTML and CSS stuff but I have a problem- I have a contact form wit

Tree Menu
Hi guys,

Can anyone help me making a tree navigation system? I have a site where I'm allowin

Placing and array within an array then sorting it!
I have a page that runs two large mysql queries and saves the results into arrays, in php I then per

Undefined Index Notice In Internet Explorer Only
I am getting the following notice:

QuoteNotice: Undefined index: jrox in /home/ycsn/public_h

When file included, REMOTE_ADDR is server's?
I have an index file that handles my site, basically index.php?page=ip will activate "require('

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