Error while connecting C program to MYSQL database [duplicate] - mysql

This question already has answers here:
MySQL and C : undefined reference to `_mysql_init#4'|
(3 answers)
Closed 7 years ago.
When I try to connect to my database I get an error :
undefined reference to 'mysql_init#4'
#include<mysql.h>
int main()
{
MYSQL *con;
con = mysql_init(NULL);
return 0;
}
I use code blocks. What is the issue?

"Undefined Reference" to something implies a linker error. In this case you are possibly not linking to the right mysql C library. Link with the appropriate C libraries.
Also, a similar question is answered here

Related

Getting result set from non-sql query [duplicate]

This question already has an answer here:
How to get Description of MySQL Table in GoLang
(1 answer)
Closed 3 years ago.
How do I retrieve data sets from non-standard MySQL "show" statement using golang? For example, "show tables", "show variables", "show engine innodb status". etc.
I cannot find any information to retrieve the result set from mysql "show" statement in Golang. Using either database/sql package or sqlx package is fine.
Got it! Here is the code. It worked!
var r1, r2, r3 string
row := db.QueryRow("show engine innodb status")
err = row.Scan(&r1, &r2, &r3)

how to use mysql lock/unlock [duplicate]

This question already has answers here:
MySQL wait_timeout Variable - GLOBAL vs SESSION
(3 answers)
Differences between SET var = 'abc' and SET GLOBAL var = 'abc'?
(1 answer)
Closed 3 years ago.
I have two questions about MySQL usage:
I installed mysql5.7 by default options.
then I connect to MySQL by MySQL query browser:
1) if I run "SET autocommit='OFF'", then I use "show variables like 'autocommit';" to check the value, but I still get the result:
autocommit='ON'.
Only if I run "SET global autocommit='OFF';" then I can see the value has been changed, why?
2) with autocommit='ON' , I want to lock a table by:
lock tables xxx write
but I can still query this table from another session.
why?

I'm having troubles selecting data from a MySQL databse [duplicate]

This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 6 years ago.
I'm attempting to make a column be included only if the ID of the column is in the web address. But it's not returning the data. Any suggestions?
This is what my code looks like
$sql="SELECT * FROM orders WHERE `orders`.`id`= '$form_id'";
$order_data=mysql_query($sql);
$form_id=$_GET['id'];
If anyone has any suggestions, please let me know.
You may use this
$form_id=$_GET['id'];
$sql="SELECT * FROM orders WHERE `orders`.`id`= '$form_id'";
$order_data=mysql_query($sql);
Hopefully this will solve your problem

Mysql AES_DECRYPT(AES_ENCRYPT()) [duplicate]

This question already has answers here:
Unable to AES_DECRYPT after AES_ENCRYPT in mysql
(4 answers)
Closed 7 years ago.
I have a problem with mysql encryption, on a mysql server 5.5.38
If I do :
SELECT AES_DECRYPT(AES_ENCRYPT("test", "123"), "123");
the result is 74657374
I saw in the mysql doc that DECODE() and ENCODE() are deprecated and that we are encouraged to use AES functions :
The ENCODE() and DECODE() functions are deprecated in MySQL 5.7, will be removed in a future MySQL release, and should no longer be used. Consider using AES_ENCRYPT() and AES_DECRYPT() instead.
Note : when I use SELECT DECODE(ENCODE("test", "123"), "123"), the result is the same : 74657374
Ok I have my answer :
SELECT CAST(AES_DECRYPT(AES_ENCRYPT('test admin','1234'),'1234') AS CHAR (50))
It was a cast issue.
Explanations here :
How to use AES_ENCRYPT and AES_DECRYPT in mysql
It's working correctly.
74657374 is a Hexidecimal representation of the string 'test':
74 = t
65 = e
73 = s
74 = t
Try using unhex:
SELECT UNHEX(AES_DECRYPT(AES_ENCRYPT("test", "123"), "123"));

"30/360 = 0" Is This A Bug Or What? [duplicate]

This question already has answers here:
SQL Server, division returns zero
(6 answers)
Why does SQL Server round off results of dividing two integers?
(6 answers)
Database calculations are wrong
(1 answer)
Closed 9 years ago.
Ok I have A SQL Procedure I calculate some Payroll Stuff. The Problem here one of my equation '30/360 = 0' return 'zero' and try it on Sql Server Like this :
Select 30/360 --This Return Zero And Should Return '0.08333333'
This is not my real function, just example, Is this normal behavior?
Dividing two integers returns an integer. Use the following instead:
select 30/360.0