Unable to connect to database

QuestionsUnable to connect to database
Jelson Bonilla asked 9 years ago

I am getting the error below.

Couldn't execute query. No database selected – SELECT * FROM clients WHERE 1=1 LIMIT 1 OFFSET 0

——————————————————————————–
Config:

<?php
$db_conf = array();
$db_conf["type"] = "mysqli";
$db_conf["server"] = "localhost"; // or your mysql ip
$db_conf["user"] = "root"; // username
$db_conf["password"] = "test"; // password
$db_conf["database"] = "griddemo"; // database

// include and create object
$base_path = strstr(realpath("."),"demos",true)."lib/";
include($base_path."inc/jqgrid_dist.php");
$g = new jqgrid($db_conf);

?>

3 Answers
Abu Ghufran answered 9 years ago

This code looks fine. If you share complete code file it would help in debugging.

$g = new jqgrid($db);

$g->con->debug = 1; // changed from 0 to 1

Try after enabling debug to see exact error. Make sure credentials are correct.

Jelson Bonilla answered 9 years ago

This is what I have.

index.php

<?php
/**
* PHP Grid Component
*
* @author Abu Ghufran <[email protected]> – http://www.phpgrid.org
* @version 1.5.2
* @license: see license.txt included in package
*/

// include db config
include_once("config.php");

// set up DB
mysql_connect('localhost','user','pass');
mysql_select_db(PHPGRID_DBNAME);

// include and create object
include(PHPGRID_LIBPATH."inc/jqgrid_dist.php");
$g = new jqgrid();

// set few params
$grid["caption"] = "Sample Grid";
$g->set_options($grid);

// set database table for CRUD operations
$g->table = "clients";

// render grid
$out = $g->render("list1");

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"&gt;
<html>
<head>
<link rel="stylesheet" type="text/css" media="screen" href="lib/js/themes/redmond/jquery-ui.custom.css"></link>
<link rel="stylesheet" type="text/css" media="screen" href="lib/js/jqgrid/css/ui.jqgrid.css"></link>

<script src="lib/js/jquery.min.js" type="text/javascript"></script>
<script src="lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
</head>
<body>
<div style="margin:10px">
<?php echo $out?>
</div>
</body>
</html>

config.php

<?php
$db_conf = array();
$db_conf["type"] = "mysqli";
$db_conf["server"] = "localhost"; // or your mysql ip
$db_conf["user"] = "root"; // username
$db_conf["password"] = ""; // password
$db_conf["database"] = "griddemo"; // database

// include and create object
$base_path = strstr(realpath("."),"demos",true)."lib/";
include($base_path."inc/jqgrid_dist.php");
$g = new jqgrid($db_conf);
$g->con->debug = 1; // changed from 0 to 1

?>

Still getting same error. How am I supposed to use the debug feature?

Your Answer

5 + 1 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?