Home  • Framework • Wordpress

Setting mysqli class access through out the WordPress project

we-use-addmenupage-to Open wp-config.php file with a text editor. add the following line just below the define( 'DB_COLLATE', '' ) line (38 no line in my case): $db=new mysqli(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME);
/** The name of the database for WordPress */
define( 'DB_NAME', 'wordpress_project4' );

/** MySQL database username */
define( 'DB_USER', 'root' );

/** MySQL database password */
define( 'DB_PASSWORD', '' );

/** MySQL hostname */
define( 'DB_HOST', 'localhost' );

/** Database charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8mb4' );

/** The database collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );

$db=new mysqli(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME);
Example: plugin function

<?php

function schools_list () {
?>

<link type="text/css" href="<?php echo WP_PLUGIN_URL; ?>/schools/style-admin.css" rel="stylesheet" />
<div class="wrap">
<h2>Schools</h2>
<a href="<?php echo admin_url('admin.php?page=create-school'); ?>">Add New</a>

<?php
global $db;
$result=$db->query("SELECT s.id,s.code,s.name,t.name type from schools s,school_type t where s.type_id=t.id");

echo "<table class='wp-list-table widefat fixed'>";
echo "<tr><th>ID</th><th>Code</th><th>Name</th><th>Medium</th><th>&nbsp;</th></tr>";


while($row=$result->fetch_object()){
	echo "<tr>";
	echo "<td>$row->id</td>";
	echo "<td>$row->code</td>";
	echo "<td>$row->name</td>";
	echo "<td>$row->type</td>";		
	echo "<td><a href='".admin_url('admin.php?page=manage-school&id='.$row->id)."'>Manage</a></td>";
	echo "</tr>";
}
echo "</table>";
?>

</div>
<?php
}

Comments 0


Share

Copyright © 2024. Powered by Intellect Software Ltd