cancel
Showing results for 
Search instead for 
Did you mean: 
Go to solution

Accessing to views in phpmyadmin

Hi for all:

 

     I am managing a database with some tables. Now I am trying to create a view and accessing it. The creation was ok, without any problem, but I cannot access from php program to that view.

I can execute the select clause relationed with that view but, when I replace the select clause with the name of the view, it does not run. 

I have created the view with the user gives by cpanel phpmyadmin access process. I connect to my database with that user without any problem too. But the view does not run.

How can I use any view from php connection process? Are there any restriction for using views in economy hosting plan (sharehosting)?

Thank you in advance

3 REPLIES 3
Super User III
Super User III

Re: Accessing to views in phpmyadmin

@Luisomanolo 

 

Good Morning - I had to google for this as I had never heard of using views before - very neat....

 

When running the PHP statement to call the view are you getting any MySQL errors??

Can you post some snippets of your code so we can see if there is any noticeable errors



I am a GoDaddy End User - Just Like You
Check out my site! | I currently manage over 300 WordPress Websites
* Please note that I offer free advice on this forum. If you would like personalized help, please contact me. Otherwise, please ask your question in the proper forum so the answer can assist EVERYONE in the community and not just you. Thanks! *

Once your issue is resolved,
please be sure to come back and click accept for the solution

Get Better Support on the Community Boards!
Etiquette When Asking for Help from the Community

Re: Accessing to views in phpmyadmin

Here you are the php:

<?
$servername = "localhost";
$username = "gooduser";
$password = "goodpassword";
$database = "MyDB";
//creating a new connection object using mysqli
$conn = new mysqli($servername, $username, $password, $database);
//if there is some error connecting to the database
//with die we will stop the further execution by displaying a message causing the error
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//if everything is fine
if ($result = $conn->query("SELECT * from vista;")) {

$row_cnt = $result->num_rows;

printf("Result set has %d rows.\n", $row_cnt);

$result->close();
}
else
echo "Nothing to show";

$conn->close();
?>

 

Vista is the View created over a table, as:

CREATE VIEW vista AS SELECT count(*) FROM table1;

 

 

where table1 is able to be seen with same user & password running this other php file:

<?
$servername = "localhost";
$username = "gooduser";
$password = "goodpassword";
$database = "MyDB";

//creating a new connection object using mysqli
$conn = new mysqli($servername, $username, $password, $database);
//if there is some error connecting to the database
//with die we will stop the further execution by displaying a message causing the error
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//if everything is fine
if ($result = $conn->query("SELECT COUNT(*) FROM TABLE1;")) {

$row_cnt = $result->num_rows;

printf("Result set has %d rows.\n", $row_cnt);

$result->close();
}
else
echo "Nothing to show";

$conn->close();
?>

The output of the first php file is:

 

Nothing to show

 

The output of the second one:

 

Result set has 1 rows.

 

I do not know the reason.

Super User III
Super User III
Solution

Re: Accessing to views in phpmyadmin

@Luisomanolo 

 

Your code all looks good, the only thing I can think of is you may have to "name" your count(*)

column 

 

I know MySQL is funny sometimes about when you do counts and use them in where clauses etc and sometimes you need a reference name vs just the count(*)

 

That's the only thing that comes to mind



I am a GoDaddy End User - Just Like You
Check out my site! | I currently manage over 300 WordPress Websites
* Please note that I offer free advice on this forum. If you would like personalized help, please contact me. Otherwise, please ask your question in the proper forum so the answer can assist EVERYONE in the community and not just you. Thanks! *

Once your issue is resolved,
please be sure to come back and click accept for the solution

Get Better Support on the Community Boards!
Etiquette When Asking for Help from the Community