Quantcast
Channel: MySQL Forums - PHP
Viewing all 938 articles
Browse latest View live

Error : (1045) Access denied for user 'root'@'localhost' (using password: NO) (4 replies)

$
0
0
Hello

I'm trying to implement a login function that allows me to extract data from facebook and save them on my moodle Website. Unfortunately, I'm not a programmer and I'm having some problems. In particular, I'm having some difficulties -I believe- related to the permission rights when I try to "write" the data extracted from fb on a MySQL database.


This is what I have done so far:

I managed to extract from Fb the data that interest me and I tried to save them to a MySQL database (created through cpannel). The code I used to access the database is basically this (with the correct parameters for my database):

// Create connection

$ Db = new mysqli ($ localhost, $ username, $ password, $ database);



// Check connection

if ($ db> connect_error) {

die ( "Connection failed:". $ db-> connect_error);

}


But when I connect to the web page I get this error: "Connection failed: Access denied for user 'root' @ 'localhost' (using password: NO)"

The problem seems to be that the user/pass are incorrect. In fact, I am sure the data correspond to those included in CPannel by me at the time of database creation. The associated user has all active privileges.


I did some research and it it seemed that the problem could be associated with some "automatic" setting of Moodle. So I uninstalled moodle but nothing has changed.

I also tried to change the code:

$config = parse_ini_file('/config.ini');

// Connect to database

$mysqli = new mysqli($config['servername'], $config['username'], $config['password'], $config['dbname']);

printf("\n ".date("Y-m-d h:i:sa") . " - Establishing connection to " . $config['dbname'] . " on " . $config['servername'] . ".\n");

// Check connection

if ($mysqli->connect_error) {

die('Error : (' . $mysqli->connect_errno . ') ' . $mysqli->connect_error);

printf("\n ".date("Y-m-d h:i:sa") . " - Connection failed. Returned error: " . mysqli_connect_error() . "\n");

} else {

printf("\n ".date("Y-m-d h:i:sa") . " - Connection successful.\n");

}

Unfortunately I had no luck ...

This is the tutorial i followed to implement the function:
https://www.youtube.com/watch?v=N5Kka43giyY&index=30&list=PLmpuiTmSb3xCLwwkpXeuJxwKyljf7e3Tx



I am very inexperienced, but it seems to me that the problem arises when I define password in cpannel ... it is as if the password had no value ..
Any ideas on how I can resolve it?



Greetings,

Ema

MySQL Query on two different servers (2 replies)

$
0
0
Hi,

Queries with joins on tables from two distinct databases work fine, as long as the databases use the same server.

SELECT fields
FROM base1.table1 INNER JOIN base2.table2 ON key1 = key2


How should I proceed when the databases are set on two distinct servers ?

thank you,

Big performance difference - can't find the reason (2 machines) ? (no replies)

$
0
0
Hello,

I have a really strange problem and I wondered if anyone of you has an idea what could cause this.

I am using a simple WP Plugin which benchmarks query performance via the following script (an excerpt):

$tableprefix = $wpdb->prefix."mywebtonetqtest";
$createtable = $wpdb->query("CREATE TABLE if not exists `$tableprefix` (`dummydata` text NOT NULL DEFAULT '')");
$time_start = microtime(true);
echo "<table width=70%>\n";
echo "<tr><td valign='top'><b>MySQL test: </b></td></tr>\n";
for ($i = 0; $i < $runquerycount ; $i++) {
$dotest = $wpdb->query( "insert into $tableprefix (dummydata) values ('$mysqlquerydata');" );
$dotest = $wpdb->query( "select * from $tableprefix;" );
$dotest = $wpdb->query( "update $tableprefix set dummydata='';" );
$dotest = $wpdb->query( "delete from $tableprefix;" );
}
$result = sprintf("%10.2f",number_format(microtime(true) - $time_start, 3));
$cresult = sprintf("%0.0f",$runquerycount /$result);


So nothing special here... the interesintg thing is that on the old machine a Core i7 6700K (4 cores 4.0Ghz) with 64GB RAM and SSD made around 350 queries/seconds in this test.

Now I moved over to a Xeon 1650v3 (6 cores 3.5Ghz) with 128GB ECC RAM and NVMe disk and the query time is down to 80/sec.

I mean thats almost 1/4 of the query performance of the old machine. Now I wonder what could cause this.

The interesting thing is I have the complete same setup and configuration.

Both using Windows Server 2016, all patches applied, latest MySQL 5.7.17, PHP 7.1.2, IIS 10 x64

I am even using a copy of the php.ini and a my.ini for SQL - so all the settings are exactly the same.

I just don't find the reason why its slower. What I can see on the new machine though is that the benchmark is using much lower CPU usage than on the old system. I thought about problems in TCP connection - but both are bound to localhost on IP4 and IP6 and there are no signs of slow delays in connecting etc. I mean i still get the 80/sec queries on new machine.

BUt how comes the old one got 300+/sec?

Maybe someone of you has an idea what or how I could check the reason for this.

Thanks a lot for your time,
Oliver

How to upgrade MySql to 5.6 (1 reply)

$
0
0
Hi,
First of all I apologize if this is not the correct place to put this question. I have just signed up today and posting my first topic here. So please bear with me.

I need to upgrade my MySql version from 5.5.54 to 5.6 on my Ubuntu 14.04 LTS PC (local development environment). I searched and found a number of posts and threads which say I can do this using apt-get.

The problem I have is I installed PHP and MySql about four ago back using Phpbrew along with other services:

$ phpbrew install php 5.6.22+default+curl+json+mysql+gd+libssh-php+asps2=/usr/bin/axps2

If now I upgrade MySql using apt-get can there be any conflict with other software and extensions I installed by Phpbrew?

1. Do I need to upgrade using Phpbrew only? If yes, do I need to use all those extensions I installed along with MySql installation? Phpbrew has the ability to install one package at a time but I am in a dilemma about my existing sites and other settings.

2. If I use apt-get, does this create another instance of MySql or upgrade the current version (because the previous version was installed using Phpbrew).

Looking for your help and advice.

Kind regards,
Subrata Sarkar

Query Using Session ID (3 replies)

$
0
0
Hi all,

Sorry I'm very new to this,

I want to do something I thought would be quite simple, that is I want to pull the users real name (first and last) from my database when they login.

The login system I am using sets up the 'username' as the session ID, which is presented in the php as $_SESSION['user']

Using mySQLi I imagined I could do something like this:



////PHP///

$_SESSSION['username'] = $username;

$result = $db->query("SELECT `firstname`, `lastname` FROM `members` WHERE username='$username'") or die($db->error);

if($result->num_rows){

$rows = $result->fetch_assoc();

}
///

Then pull it from the array and just insert it in to the site header, however I can return this in any permutation I try.

Anybody point to what I'm doing wrong?

How can i update an existing column with new data (8 replies)

$
0
0
Hello

I'm building my own CMS to insert records to my DB but i've made a small mistake when entering the new data.

I have a table called "countries" with fields id, country_name, id_continents and id_flag.

Then i have a form to insert those records but for the id_flag i've set it for an Int and was giving id numbers when inserting each country. What i was supposed to do was to insert the Url for the country image thumbnail instead of an id!

How can i use the same form to enter just the url of the thumbnails and the corresponding country ID ?

Below this is my form code:

<div class="wrapper">
<form action="BackOffice.php" method="post" class="form">
<fieldset>
<legend>Paises:</legend>

<div class="campos"><label for="nome_país">País: </label> <input type="text" name="nome_país"><br></div>

<div class="campos"><label for="continente">idContinente: </label> <input type="text" name="idContinente"><br></div>

<div class="campos"><label for="bandeiras">urlBandeiras: </label> <input type="file" name="urlBandeiras"><br></div>
<button type="submit" class="envio" name="btn_paises" value="true">Enviar</button>
</fieldset>
</form>


And this is the code to insert data using Prepared Statements:

if(isset($_POST['btn_paises'])) {
$stmt = $mysqli->prepare("INSERT INTO countries(country_name, id_continentes, id_flag ) VALUES(?,?,?)");
$stmt->bind_param('sis', $_POST['nome_país'], $_POST['idContinente'], $_POST['urlBandeiras']);
$stmt->execute();

$mysqli->close();
}

Fatal error: Uncaught Error: Call to undefined function mysql_query() in C:\xampp\htdocs\SecretShop\Customers\shop.php:317 Stack trace: #0 {main} thrown in C:\xampp\htdocs\SecretShop\Customers\shop.php on line 317 (2 replies)

$
0
0
$query1=mysqli_connect("127.0.0.1","root","1234");
mysqli_select_db($query1,"edgedata");

$start=0;
$limit=8;

if(isset($_GET['id']))
{
$id=$_GET['id'];
$start=($id-1)*$limit;
}

$query=mysqli_query("select * from items LIMIT $start, $limit");


while($query2=mysql_fetch_array($query))
{

echo "<div class='col-sm-3'><div class='panel panel-default' style='border-color:#008CBA;'>
<div class='panel-heading' style='color:white;background-color : #033c73;'>
<center>
<textarea style='text-align:center;background-color: white;' class='form-control' rows='1' disabled>".$query2['item_name']."</textarea>
</center>
</div>
<div class='panel-body'>
<a class='fancybox-buttons' href='../Admin/item_images/".$query2['item_image']."' data-fancybox-group='button' title='Page ".$id."- ".$query2['item_name']."'>

<img src='../Admin/item_images/".$query2['item_image']."' class='img img-thumbnail' style='width:350px;height:150px;' />
</a>


<center><h4> Price: &#8369; ".$query2['item_price']." </h4></center>


<a class='btn btn-block btn-danger' href='add_to_cart.php?cart=".$query2['item_id']."'><span class='glyphicon glyphicon-shopping-cart'></span> Add to cart</a>

Server lag or join problem? (3 replies)

$
0
0
I'm using the following join via php. Testing through phpadmin the time it takes to initially return the recordset is almost 30 seconds!! hitting refresh takes only 0.0002 seconds. Could this be a server issue or is there something fundamentally wrong with my sql? Here's the sql:
SELECT a.article_id, a.article_heading, a.article_text, a.article_link, i.image_name, i.image_title
FROM articles AS a
LEFT JOIN images as i ON (a.article_id = i.parent_id AND i.parent_table = 'articles' AND i.display_order = 1)
LEFT JOIN categories as c ON (a.article_id = c.parent_id AND c.parent_table = 'articles')
WHERE a.navigation_id = x AND a.module_id = x AND a.live = 1
GROUP BY a.article_id
ORDER BY a.display_order DESC
LIMIT 4;

problem inserting data from a web form (2 replies)

$
0
0
I am having problems inserting data into my MySQL database from a webform. I have simplified the values by typing in text values as below. I am thinking the MySQL_query command may not be correct. Any help would be much appreciated.

<?php

$sql = "INSERT INTO login (username, password, email, password2) VALUES ('greg1', 'greg2', 'greg3@hello.com', 'greg4')";

mysql_query($sql);

mysql_close($conn);


?>

Failed to connect to MySQL: (2003) Can't connect to MySQL server on 'localhost' (10061) (1 reply)

$
0
0
Hi,
I´m using MAMP with PHP and Mysql server
I get an error message when I try to open the database using php.
The error message is:
Failed to connect to MySQL: (2003) Can't connect to MySQL server on 'localhost' (10061)

And the php code used is:

<?php
$mysqli = new mysqli("localhost", "javier", "", "ejemplo");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
echo $mysqli->host_info . "\n";

?>

Can anyone help, please?
many thanks Jav

Join 2 tables and store in 3rd table (1 reply)

$
0
0
Hello everyone

I've an issue:

I have following 2 tables

¦---bb_tickets---¦
¦ id ¦ owner ¦
¦----------------¦
¦ 111 ¦ 2 ¦
¦ 145 ¦ 2 ¦
¦ 152 ¦ 3 ¦
¦----------------¦


¦---bb_users-----¦
¦ id ¦ user ¦
¦--------------- ¦
¦ 1 ¦ Admin ¦
¦ 2 ¦ PG ¦
¦ 3 ¦ FS ¦
¦----------------¦


i'd like to export in the 3rd table following data:


¦----Result----¦
¦ id ¦ user ¦
¦--------------¦
¦ 111 ¦ PG ¦
¦ 145 ¦ PG ¦
¦--------------¦



Have you idea if I must use the JOIN, and if yes, how to?

Thanks in advance

PG

Select one row for each day (5 replies)

$
0
0
Greetings,

First, forgive me. I'm a noob and I'm struggling to put together a SELECT statement.

I have a table (WEATHER_MEASUREMENT) that is getting a new row added every ten minutes (weather data). One of the fields is called "AIR_PRESSURE".

I would like to be able to query the table for the first reading of each day for 7 days, for displaying barometric pressure trends.

I've tried to use "LIMIT" but the problem I'm having is in the "CREATED" column, (which is a timestamp), every entry is unique because the time is included in the timestamp.

The columns I'm interested in are 'CREATED' and 'AIR_PRESSURE' and if it's possible, strip the time from the 'CREATED' field.

Once I can do this, I can just limit it to 7 and I'll be good to go. Any help is greatly appreciated!

Brian

Need query as a variable not object (1 reply)

$
0
0
I'm doing a select on a database in PHP to grab the datestamp from the most recent row and passing it to another include file.

I'm using this code:

$result = mysqli_query($link, 'SELECT CREATED FROM WEATHER_MEASUREMENT ORDER BY ID DESC LIMIT 1');

I need $result to be regular variable, not an object. Since I only need one single cell, it seems silly to do a "foreach" for this.

To display the date in another file, I'm using:

<?php $result = $date?>
<?php $time = strtotime($date);?>
<?php $mytimeformat = date("m/d/y g:i A", $time);?>
<?php echo $mytimeformat; ?>

I'm getting this error:

"Expects parameter 1 to be string, array given in /var/www/html/readings.html.php on line 22"

But what does work is this:

<?php date_default_timezone_set("America/Phoenix");?>
<?php foreach ($mydate as $date): ?>
<?php endforeach; ?>
<?php $time = strtotime($date);?>
<?php $mytimeformat = date("m/d/y g:i A", $time);?>
<?php echo $mytimeformat; ?>

How can I do this without having to do a 'foreach' for a single row?

Thanks!

Brian

MySQL and phpBB3 anonymous user configuration (2 replies)

$
0
0
I tried this a while back where I read a few articles that the anonymous user should be removed.
Well, I removed the anonymous user and no longer could I view the forum to access it/log in to it.

I finally redid the installation for phpBB3/MySQL and am reading again that the anonymous user is only for test purposes. That it should be removed.

I am hoping someone can explain to me why I had an issue last time I removed the user and how I can make this new installation more secure while still being able to use the forum.

I am wondering if I can just change the password for anonymous, but I vaguely remember trying that in the past and had the same issue with viewing the login page.

Any help would be very mush appreciated.

Thanks in advance.

How to interact with mysql user database from Android application? (no replies)

$
0
0
I am working on a mobile application created by Unity3D(using c#) then exported as Android project. The application is designed to put sensors in a room with augmented reality then monitor and visualize data of each sensor. So for each user, I need to deal with two types of information: the Area Description File(for positioning indoor), and data of all sensors. The Area Description File is generated by my application, which needs to be stored in database, and the data of sensors is obtained by an uploading system and put into the database in real-time.

To realize this, I have made researches and now I'll roughly describe what I want to do:

(1) In my application, use login.php to authenticate user by comparing user information stored in mysql database table1 and then get user_id:

table1:

user_id, user_name, password, email
1, Tom, 123456, Tom@xx.com
2, Alex, 111111, Alex@xx.com

(2) With user_id, use get_ADF_file.php to make queries in table2 to get the Area Description File directory location, so that the user can download the Area Description File in the app.

table2:

user_id, ADF_file_id, ADF_file_directory_location
1, 1, download_link1
1, 2, download_link2
2, 1, download_link3

(3) Now that I have ADF file, the next step is to get all sensor data by using get_sensor_data.php to make queries in a particular table with user_id and sensor_id. For example, if the user_id is 1, the sensor_id is 2, then the queries will be made in table_1_2.

table_1_1:

user_id, sensor_id, time, data_value
1 , 1 , 0 , 10,
1 , 1 , 1 , 11,
1 , 1 , 2 , 12 ,
...

table_1_2:

user_id, sensor_id, time, data_value
1, 2, 0 , 5
1, 2, 1, 6
1, 2, 2, 8
...

Basically that is what I thought to interact with database from my application in a simple way, is that a possible way? Please tell me if there is something wrong and show me a right way to do this. Thanks!

myPHAdmin give different results than PHP select (no replies)

$
0
0
Greetings,

I'm a newbie so please bear with me. I am working with an RPi and 'inserting' into a MySQL database from Python. That part works fine.

Forgive me if I give you too much info but I want things to be in context so you can understand my configuration.

Using my RPi, (Raspberry Pi 3 B) I read temp, humidity and barometric pressure sensors and insert them into my DB called 'weather'. I then query a table called 'WEATHER_MEASUREMENTS' to display various data in a website hosted locally using lighttpd.

One of the things I wish to display is the last 24 hours of barometric pressure.

I currently insert temperature, humidity and barometric pressure into my DB once every 10 minutes. In order to display weather trends I wish to show barometric pressure readings over 24 hours. Since I take 6 readings per hour, I wanted limit it to ten readings over 24 hours, equally spaced. I took this to be equivalent to 'mod 14'. I wish to display to two columns, 'AIR_PRESSURE' and 'CREATED'. CREATED is a 'timestamp' column.

I have two files I work with; my index.php and readings.html.php. At the end of the index.php file is an 'include' line that reads: include 'readings.html.php';

My initial query is done in the index.php and looks like this:

$result = mysqli_query($link, 'Select ID, CREATED, DATE(CREATED), AIR_PRESSURE
FROM WEATHER_MEASUREMENT WHERE mod(ID,14) = 0 GROUP BY CREATED ORDER BY ID DESC LIMIT 10');
if (!$result)
{
$error = 'Error fetching date : ' . mysqli_error($link);
include 'error.html.php';
exit();
}

while ($row = mysqli_fetch_array($result))
{
$prevdaypress[] = $row['AIR_PRESSURE'];
$prevdaytime[] = $row['CREATED'];
}
$testarray=array_combine($prevdaypress, $prevdaytime);

Then in my 'readings.html.php' I have this:

<?php foreach ($testarray as $prevdaystuff): ?>
<?php echo ($prevdaystuff)?><br>
<?php endforeach; ?>

And this is my output on my web page:

2017-05-01 17:58:33
2017-05-01 15:37:53
2017-05-01 13:17:19
2017-05-01 10:56:37
2017-05-01 08:35:47
2017-05-01 06:14:54
2017-04-30 23:13:43
2017-04-30 20:53:19

There are two things to note; the barometric pressure isn't in the list, which should be there from the line, '$prevdaypress[] = $row['AIR_PRESSURE'];'.

Also, notice the large gap between, '2017-04-30 23:13:43' and '2017-05-01 06:14:54'. The gap should only be a max of about 2.5 hours if you do the math.

I've tried a bunch of different combinations of this query, etc. and sometimes I have a date from April mixed in between two 'May dates'.

I hope I've provide enough information. I wanted to give a good idea of what I was doing and what I wanted to achieve. Your help is appreciated!

extracting data including json array from joined tables (no replies)

$
0
0
Hello,

Developers our company paid to write an app for us used json data which i've never accessed.

I'm new to mysql and phpmyadmin but i want to do some simple select statements and one is to pull transaction data from a table that has regular data and json data. I need to join two tables and i can get the data to pull for a single row of data but not more than that.

I'm trying to do this in the phpmyadmin console and our developers don't want to part with the info even if i pay for the time it takes to pass it on.

Can anyone help? Basic query i'm using is below.

Thanks very much!

SELECT
`id`,
`user`,
`hotelID`,
`cartID`,
`RoomId`,
`meta_value`
FROM
`wp_cart` a
INNER JOIN
`wp_usermeta` b ON b.user_id = `id`
WHERE
`meta_key` = 'xyz_MemberNo'

select retailers from categories (no replies)

$
0
0
I'm struggling with this

table1
categories category_id

table2
retailer_to_category retailer_id and category_id

table3
retailers retailer_id title and retailer_url

in my first page i have all categories, when one category selected it opens new page with all retailers in this category. When i use following code it returns 0 results

can enywhone help me solve this. Should i use 'where'?



$sql = "SELECT
categories.category_id,
retailers.retailer_id,
retailers.retailer_url,
retailers.title,
retailer_to_category.category_id
FROM retailer_to_category
INNER JOIN categories
ON categories.category_id = retailer_to_category.retailer_id
INNER JOIN retailers
ON retailers.retailer_id = retailer_to_category.retailer_id
ORDER BY retailers.title";

if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {


echo "<a href= " . $row["retailer_url"]. " target='_blank'> " . $row["title"]. "</a><br>";
}
} else {
echo "0 results";
}
$conn->close();
?>

SQLSTATE[HY000] [2002] Connection timed out (1 reply)

$
0
0
Hi,

I keep getting above error when trying to connect from PHP but I am able to connect using the same credentials from Navicat.

This is the error:

<br />
<b>Fatal error</b>: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] Connection timed out' in /home/meskholdings/cakeboutiquebh.com/ws/verify_customer_app_id2.php:21
Stack trace:
#0 /home/meskholdings/cakeboutiquebh.com/ws/verify_customer_app_id2.php(21): PDO-&gt;__construct('mysql:host=88.2...', 'root', 'xxxxxx', Array)
#1 {main}
thrown in <b>/home/meskholdings/cakeboutiquebh.com/ws/verify_customer_app_id2.php</b> on line <b>21</b><br />


and this is my PHP:

header("Content-Type: application/json");

if (isset($_SERVER['HTTP_ORIGIN'])) {
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400'); // cache for 1 day
}

$classification = $_POST["cl"];

$mysql_host = "mysql:host=xxx.xxx.xxx.xxx;port=3366;dbname=savanna";
$mysql_user = "root";
$mysql_password = "xxxx;
$mysql_options = array
(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
);

// $mysql_connection;
$mysql_connection = new PDO($mysql_host, $mysql_user, $mysql_password, $mysql_options);
$mysql_connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);


Kindly help


Thanks,
Jassim

Strange behavour (1 reply)

$
0
0
Hello

I am already programing for many year already now i faced a real strange issue
I have query which verify for duplicate id and tid

$query4=mysql_query("select id,tid from transactionlog where id='$result1[id]' and tid ='$result1[tid ]'") ;

$num=mysql_num_rows($query4);
if ($num == 0)
{
// case new . insert new raw here
}

The db i am using is fairly big over 500k raw , now the strange part is that this query sometime return num_rows 0 even when id and tid exist ,
this happen in about 1 time each few million queries ,
by the way i am using 5.6.35-log under windows (i need mysql old_password function that's why i am using older version ).
I know it is possible to setup id and tx as primary and unique , but i really want to know how come num_rows returning 0 while it should have 1 . is it know bug that i am missing ?

anyone faced similar issue ???
Viewing all 938 articles
Browse latest View live


Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>